package Test;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class TestDemo3 {
    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();
        new Thread(()->{
            phone.sendmsg();
        },"A").start();
        TimeUnit.SECONDS.sleep(1);
        new Thread(()->{
            phone.call();
        },"B").start();
    }
}
class Phone {

    public synchronized void sendmsg() {
        System.out.println(Thread.currentThread().getName()+"发短信");
    }

    public synchronized void call() {
        System.out.println(Thread.currentThread().getName()+"打电话");
    }
}
